$(function() {
	$("#jqGrid").jqGrid({
		url: baseURL + 'wisarchivesperson/list',
		datatype: "json",
		colModel: [{
				label: 'pid',
				name: 'pid',
				index: 'pid',
				width: 50,
				key: true,
				hidden: true
			},
			{
				label: '',
				name: 'sysSeq',
				index: 'sysSeq',
				width: 80,
				hidden: true
			},
			{
				label: '组别',
				name: 'personGroup',
				index: 'personGroup',
				width: 80
			},
			{
				label: '姓名',
				name: 'personName',
				index: 'personName',
				width: 80
			},
			{
				label: '性别',
				name: 'personSex',
				index: 'personSex',
				width: 80
			},
			{
				label: '年龄',
				name: 'personAge',
				index: 'personAge',
				width: 80
			},
			{
				label: '身份证号码',
				name: 'personIdcard',
				index: 'personIdcard',
				width: 80,
				hidden: true
			},
			{
				label: '家庭人数',
				name: 'personFamilyNums',
				index: 'personFamilyNums',
				width: 80,
				hidden: true
			},
			{
				label: '家庭关系',
				name: 'personFamilyRelation',
				index: 'personFamilyRelation',
				width: 80,
				hidden: true
			},
			{
				label: '户主',
				name: 'personFamilyHeader',
				index: 'personFamilyHeader',
				width: 80
			},
			{
				label: '政治面貌',
				name: 'personPolitical',
				index: 'personPolitical',
				width: 80,
				hidden: true
			},
			{
				label: '婚姻状况',
				name: 'personMarry',
				index: 'personMarry',
				width: 80,
				formatter: function(cellvalue, options, rowObject) {
					var text = '未婚';
					//数字对应中文匹配
					switch(rowObject.personMarry) {
						case 0:
							text = '未婚';
							break;
						case 1:
							text = '已婚';
							break;
						case 2:
							text = '离异';
							break;
						case 3:
							text = '再婚';
							break;
						case 4:
							text = '丧偶';
							break;
						default:
							break;
					}
					return text;
				}
			},
			{
				label: '民族',
				name: 'personNational',
				index: 'personNational',
				width: 80
			},
			{
				label: '文化程度',
				name: 'personEducation',
				index: 'personEducation',
				width: 80,
				formatter: function(cellvalue, options, rowObject) {
					var text = '未婚';
					//数字对应中文匹配
					switch(rowObject.personEducation) {
						case 0:
							text = '文盲';
							break;
						case 1:
							text = '小学';
							break;
						case 2:
							text = '初中';
							break;
						case 3:
							text = '高中';
							break;
						case 4:
							text = '大学';
							break;
						case 5:
							text = '硕士';
							break;
						case 6:
							text = '博士';
							break;
						default:
							break;
					}
					return text;
				}
			},
			{
				label: '在校生状况',
				name: 'personAtschool',
				index: 'personAtschool',
				width: 80,
				hidden: true
			},
			{
				label: '健康状况',
				name: 'personHealth',
				index: 'personHealth',
				width: 80,
				hidden: true
			},
			{
				label: '劳动能力',
				name: 'personLabor',
				index: 'personLabor',
				width: 80,
				hidden: true
			},
			{
				label: '务工状况',
				name: 'personWorkSituation',
				index: 'personWorkSituation',
				width: 80,
				hidden: true
			},
			{
				label: '家庭属性',
				name: 'personFamilySituation',
				index: 'personFamilySituation',
				width: 80
			},
			{
				label: '人均年收入',
				name: 'personIncomeYear',
				index: 'personIncomeYear',
				width: 80
			},
			{
				label: '联系电话',
				name: 'personMobile',
				index: 'personMobile',
				width: 80,
				hidden: true
			},
			{
				label: '头像',
				name: 'personPic',
				index: 'personPic',
				width: 80,
				hidden: true
			},
			{
				label: '',
				name: 'sysCreateTime',
				index: 'sysCreateTime',
				width: 80,
				hidden: true
			},
			{
				label: '',
				name: 'lastModifyTime',
				index: 'lastModifyTime',
				width: 80,
				hidden: true
			},
			{
				label: '操作',
				name: '操作',
				index: '',
				width: 80,
				sortable: false,
				formatter: function(cellvalue, options, rowObject) {
					return '<button style="border:0px" class="btn btn-default btn-xs" onclick="view(\'' + rowObject.pid + '\')"><i class="fa fa-eye"></i></button>';
				}
			}
		],
		viewrecords: true,
		height: 385,
		rowNum: 10,
		rowList: [10, 30, 50],
		rownumbers: true,
		rownumWidth: 25,
		autowidth: true,
		multiselect: true,
		pager: "#jqGridPager",
		jsonReader: {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames: {
			page: "page",
			rows: "limit",
			order: "order"
		},
		gridComplete: function() {
			//隐藏grid底部滚动条
			$("#jqGrid").closest(".ui-jqgrid-bdiv").css({
				"overflow-x": "hidden"
			});
		}
	});
});

var vm = new Vue({
	el: '#rrapp',
	data: {
		showList: true,
		title: null,
		wisArchivesPerson: {},
		radio_checked_personSex: false,
		//家庭关系
		personFamilyRelationOptions: [
			'户主',
			'配偶',
			'之子',
			'之女'
		],
		//婚姻情况
		personMarryOptions: [{
				'text': '未婚',
				'value': 0
			},
			{
				'text': '已婚',
				'value': 1
			},
			{
				'text': '离异',
				'value': 2
			},
			{
				'text': '再婚',
				'value': 3
			},
			{
				'text': '丧偶',
				'value': 4
			}
		],
		//文化程度
		personEducationOptions: [{
				'text': '文盲',
				'value': 0
			},
			{
				'text': '小学',
				'value': 1
			},
			{
				'text': '初中',
				'value': 2
			},
			{
				'text': '高中',
				'value': 3
			},
			{
				'text': '大学',
				'value': 4
			},
			{
				'text': '硕士',
				'value': 5
			},
			{
				'text': '博士',
				'value': 6
			}
		]

	},
	methods: {
		query: function() {
			vm.reload();
		},
		add: function() {
			vm.showList = false;
			vm.title = "新增";
			vm.wisArchivesPerson = {};
		},
		update: function(event) {
			var pid = getSelectedRow();
			if(pid == null) {
				return;
			}
			vm.showList = false;
			vm.title = "修改";

			vm.getInfo(pid)
		},
		saveOrUpdate: function(event) {
			var url = vm.wisArchivesPerson.pid == null ? "wisarchivesperson/save" : "wisarchivesperson/update";
			$.ajax({
				type: "POST",
				url: baseURL + url,
				contentType: "application/json",
				data: JSON.stringify(vm.wisArchivesPerson),
				success: function(r) {
					if(r.code === 0) {
						alert('操作成功', function(index) {
							vm.reload();
						});
					} else {
						alert(r.msg);
					}
				}
			});
		},
		del: function(event) {
			var pids = getSelectedRows();
			if(pids == null) {
				return;
			}

			confirm('确定要删除选中的记录？', function() {
				$.ajax({
					type: "POST",
					url: baseURL + "wisarchivesperson/delete",
					contentType: "application/json",
					data: JSON.stringify(pids),
					success: function(r) {
						if(r.code == 0) {
							alert('操作成功', function(index) {
								$("#jqGrid").trigger("reloadGrid");
							});
						} else {
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(pid) {
			$.get(baseURL + "wisarchivesperson/info/" + pid, function(r) {
				vm.wisArchivesPerson = r.wisArchivesPerson;
				//初始化组件的值
				vm.radio_checked_personSex = vm.wisArchivesPerson.personSex == '男' ? true : false;
			});
		},
		reload: function(event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
				page: page
			}).trigger("reloadGrid");
		}
	}
});